"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_data_start = binder_py('mx_eyelink_data_start')
eyelink_data_start.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
eyelink_data_start.bindo += ['utils.o']
eyelink_data_start.mx_c.code = \
"""
INT16 _main( UINT16 flag, INT16 lock )
{
    return eyelink_data_start( flag, lock); 
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    int f,l;
    
    /* Verify input arguments. */
    if( nrhs != 2 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    
    if ( isscalar( prhs[0] ) ){
        if (returnscalar( prhs[0], &f ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                             if ( f < 0 )
            mexErrMsgTxt("flag should be positive.");
    } else {
         mexErrMsgTxt("flag should be scalar.");
    } 
    
    if ( isscalar( prhs[1] ) ){
        if (returnscalar( prhs[1], &l ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                     
    } else {
         mexErrMsgTxt("lock should be scalar.");
    } 

    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    *status = (double ) _main( (UINT16 ) f, (INT16 ) l );
        
    return;
}
"""

eyelink_data_start.mx_c.mdoc = \
"""function [ ] = mx_eyelink_data_start( )
%MX_EYELINK_DATA_START Switches tracker to Record mode, enables data types for
% recording to EDF file or sending to link. These types are set with a bitwise 
% OR of these flags:
%
% RECORD_FILE_SAMPLES (1) - only active if file open.
% RECORD_FILE_EVENTS (2) - only active if file open.
% RECORD_LINK_SAMPLES (4) - accept samples from link.
% RECORD_LINK_EVENTS (8) - accept events from link.
%
% Remarks:
% If <lock> is nonzero, the recording may only be terminated through 
% stop_recording() or eyelink_data_stop(), or by the Abort menu (‘Ctrl’ ’Alt’
% ’A’ keys on the eye tracker). If zero, the tracker 'ESC' key may be used to
% halt recording.
%
% Parameters:
% flags 	Bitwise OR of flags to control what data is recorded. If 0,
% recording will be stopped.
% lock 	If nonzero, prevents 'ESC' key from ending recording.
% Returns:
% 0 if command sent OK, else link error.
"""
eyelink_data_start.write_c()
eyelink_data_start.write_m()
eyelink_data_start.compile()
eyelink_data_start.write_sh()

